/**
 * 
 */
package truerefactor.graph;

import java.util.ArrayList;
import java.util.List;

/**
 * StatementNode - CodeNode implementation used to model a single statement
 * within a method
 * 
 * @author Isaac Griffith
 */
public class StatementNode extends CodeNode {

    /**
     * Parent method node in which this statement is contained
     */
    private MethodNode parent;

    /**
     * @return the parent method of this statement
     */
    public MethodNode getParent()
    {
        return parent;
    }

    /**
     * Sets the parent method of this statement to be the provided methodnode
     * 
     * @param parent
     *            the new parent method of this statement
     */
    public void setParent(MethodNode parent)
    {
        this.parent = parent;
    }

    /**
     * Creates a new instance of StatementNode with the given MethodNode as its
     * parent, StaementType as its identifier, and code
     * 
     * @param parent
     *            the parent MethodNode of this statement
     * @param type
     *            the statement type from which the identifier comes
     * @param code
     *            the underlying code for the statement
     */
    public StatementNode(MethodNode parent, StatementType type, String code)
    {
        this(type.getIdentifier(), code);
        this.parent = parent;
    }

    /**
     * Creates a new StatementNode with the given identifier and code
     * 
     * @param identifier
     *            identifier (type) of this statement
     * @param code
     *            underlying code of this statement
     */
    private StatementNode(String identifier, String code)
    {
        this(CodeGraph.nextUID(), identifier, code);
    }

    /**
     * Creates a new StatementNode with the given unique id, identifier, and
     * code.
     * 
     * @param uid
     *            unique id
     * @param identifier
     *            statement identifier (type)
     * @param code
     *            code of this statement
     */
    private StatementNode(long uid, String identifier, String code)
    {
        super(uid, identifier, code);
    }

    /*
     * (non-Javadoc)
     * @see truerefactor.graph.CodeNode#add(truerefactor.graph.CodeNode)
     */
    @Override
    public void add(CodeNode child)
    {
    }

    /*
     * (non-Javadoc)
     * @see truerefactor.graph.CodeNode#remove(truerefactor.graph.CodeNode)
     */
    @Override
    public void remove(CodeNode child)
    {
    }

    /*
     * (non-Javadoc)
     * @see truerefactor.graph.CodeNode#getChild(java.lang.String)
     */
    @Override
    public CodeNode getChild(String identfier)
    {
        return null;
    }

    @Override
    public List<CodeNode> getChildren()
    {
        return new ArrayList<CodeNode>();
    }

    /*
     * (non-Javadoc)
     * @see truerefactor.graph.CodeNode#clone()
     */
    @Override
    public Object clone() throws CloneNotSupportedException
    {
        StatementNode node = new StatementNode(uid, new String(this.identifier), new String(this.code));

        return node;
    }

    /**
     * Sets the value of this statement's code to be the string provided
     * 
     * @param string
     *            new value for code
     */
    public void setCode(String string)
    {
        this.code = string;
    }
}
